package com.psychology.controller;

import com.psychology.dto.UserDTO;
import com.psychology.result.BaseReturnRvo;
import com.psychology.service.UserService;
import com.psychology.vo.UserVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@RestController
@RequestMapping("/api-process")
@Slf4j
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 登录
     *
     * @param userDTO
     * @return
     */
    @PostMapping("/login")
    public BaseReturnRvo<UserVO> login(@RequestBody UserDTO userDTO) {
        log.info("用户登录：{}", userDTO);
        return BaseReturnRvo.success(userService.login(userDTO));
    }
    /**
     * 注册
     * @param userDTO
     * @return
     */
    @PostMapping("/register")
    public BaseReturnRvo register(@RequestBody UserDTO userDTO){
        log.info("注册用户：{}",userDTO);
        userService.registerUser(userDTO);
        return BaseReturnRvo.success();
    }


    /**
     * 查找账号
     * @param accountId 账号id
     * @return
     */
    @GetMapping("/getByAccountId")
    public BaseReturnRvo<UserVO> getByAccountId(@RequestParam String accountId){
        log.info("账号：{}",accountId);
        return BaseReturnRvo.success(userService.getByAccountId(accountId));
    }

    /**
     * 重置账号密码
     * @param userDTO
     * @return
     */
    @PostMapping("/passwords/recover")
    public BaseReturnRvo recoverPassword(@RequestBody UserDTO userDTO){
        log.info("用户信息：{}",userDTO);
        userService.recoverPassword(userDTO);
        return BaseReturnRvo.success();
    }

    /**
     * 退出
     *
     * @return
     */
    @PostMapping("/logout")
    @ApiOperation("用户工退出")   //value属性可以省略，直接写描述
    public BaseReturnRvo<String> logout() {
        return BaseReturnRvo.success();
    }


    /**
     * 获取用户信息
     * @param accountId 账号id
     * @return
     */
    @GetMapping("/getUserInfo")
    public BaseReturnRvo<UserVO> getUserInfo(@RequestParam String accountId){
        log.info("账号：{}",accountId);
        return BaseReturnRvo.success(userService.getByAccountId(accountId));
    }
}